package com.pi.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author TomFang
 * @version 1.0
 * @description: 元数据填充配置
 * @date 2025/3/28 14:59
 */
@Component
public class MyBatisPlusObjectConfig implements MetaObjectHandler {

    private  final Logger  log = LoggerFactory.getLogger(MyBatisPlusObjectConfig.class);

    /**
     * 插入
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        try {
            this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
            this.strictInsertFill(metaObject,"updateTime",Date.class, new Date());
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }

    /**
     * 更新
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        try{
            this.strictInsertFill(metaObject,"updateTime",Date.class, new Date());
        }catch (Exception e){
            log.error(e.getMessage());
        }
    }
}
